import { createI18n } from "vue-i18n";

function loadStores() {
    const locals = require.context('./', true, /[A-Za-z0-9-_,\s]+\.ts$/i)
    const obj: { [key: string]: any } = {}
    locals.keys().forEach(key => {
        const mateched = key.match(/([A-Za-z0-9-_]+)\./i)
        if (mateched && mateched.length > 1) {
            if (mateched[1] != 'i18n') {
                const locale = mateched[1]
                obj[locale] = require(`./${locale}`)
            }
        }
    })
    return obj
}

const modules = loadStores()

const i18n = createI18n({
    globalInjection: true,
    legacy: false,
    locale: localStorage.getItem('LANG') || 'zh',
    messages: modules
})
export default i18n